home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 6 / develop 6 code / TCP / NewsWatcher / NewsWatcher 2.0d15 source / source / mouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-11  |  3.7 KB  |  165 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     mouse.c
  4.  
  5.     This module handles mousedown events.
  6.     
  7.     Portions copyright © 1990, Apple Computer.
  8.     Portions copyright © 1993, Northwestern University.
  9.  
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include "glob.h"
  13. #include "article.h"
  14. #include "close.h"
  15. #include "cmd.h"
  16. #include "key.h"
  17. #include "collapse.h"
  18. #include "draw.h"
  19. #include "mouse.h"
  20. #include "resize.h"
  21. #include "scroll.h"
  22. #include "send.h"
  23. #include "util.h"
  24. #include "wind.h"
  25. #include "drag.h"
  26.  
  27.  
  28. /*    DoDrag handles window drags */
  29.  
  30. static void DoDrag (WindowPtr wind, Point globMouse)
  31. {
  32.     Rect oldRect, newRect;
  33.     GrafPtr savePort;
  34.     WStateData **stateHndl;
  35.     short deltaH, deltaV;
  36.  
  37.     GetPort(&savePort);
  38.     SetPort(wind);
  39.     stateHndl = (WStateData**)((WindowPeek)wind)->dataHandle;
  40.     oldRect = wind->portRect;
  41.     LocalToGlobal((Point*)&oldRect.top);
  42.     DragWindow(wind, globMouse, &gDragRect);
  43.     newRect = wind->portRect;
  44.     LocalToGlobal((Point*)&newRect.top);
  45.     deltaH = newRect.left - oldRect.left;
  46.     deltaV = newRect.top - oldRect.top;
  47.     OffsetRect(&(**stateHndl).stdState, deltaH, deltaV);
  48.     OffsetRect(&(**stateHndl).userState, deltaH, deltaV);
  49.     SetPort(savePort);
  50. }
  51.  
  52.  
  53. /* HandleContent: Handles mouse-downs within content of window */
  54.  
  55. static void HandleContent (WindowPtr wind, EventRecord *ev)
  56. {
  57.     GrafPtr savePort;
  58.     TWindow **info;
  59.     short part;
  60.     Boolean extendClick;
  61.     TEHandle theTE;
  62.     ControlHandle control;
  63.     EWindowKind kind;
  64.         
  65.     if (wind != FrontWindow()) {
  66.         SelectWindow(wind);
  67.         return;
  68.     }
  69.     
  70.     GetPort(&savePort);
  71.     SetPort(wind);
  72.     GlobalToLocal(&ev->where);
  73.  
  74.     info = (TWindow**) GetWRefCon(wind);
  75.     kind = (**info).kind;
  76.     
  77.     switch (kind) {
  78.         case kFullGroup:
  79.         case kNewGroup:
  80.         case kUserGroup:
  81.         case kSubject:
  82.             if (kind == kSubject && TriangleClick(wind, ev->where)) break;
  83.             if (kind != kSubject) BeginGroupListClick();
  84.             if (LClick(ev->where, ev->modifiers, (**info).theList))
  85.                 OpenSelectedCells(wind);
  86.             break;
  87.         case kArticle:
  88.         case kMiscArticle:
  89.         case kPostMessage:
  90.         case kMailMessage:
  91.             theTE = (**info).theTE;
  92.             if ((part = FindControl(ev->where, wind, &control)) != 0) {
  93.                 if (GetCRefCon(control) == kSendButton) {
  94.                     if (TrackControl(control, ev->where, nil) != 0) {
  95.                         if (DoSendMsg(wind)) DoCloseWindow(wind);
  96.                     }
  97.                 } else {
  98.                     DoScrollers(control, part, ev->where);
  99.                 }
  100.             }
  101.             else {
  102.                 if (PtInRect(ev->where, &((**theTE).viewRect))) {
  103.                     extendClick = ((ev->modifiers & shiftKey) != 0);
  104.                     TEClick(ev->where,extendClick, theTE);
  105.                     if ((ev->modifiers & optionKey) != 0) 
  106.                         OpenSelectedReference(wind);
  107.                 }
  108.             }
  109.             break;
  110.         case kStatus:
  111.             if ((part = FindControl(ev->where, wind, &control)) != 0 &&
  112.                 TrackControl(control, ev->where, nil) != 0)
  113.                 gCancel = true;
  114.             break;
  115.     }
  116.     SetPort(savePort);
  117. }
  118.  
  119.  
  120. /* HandleMouseDown handles mouse down events */
  121.  
  122. void HandleMouseDown (EventRecord *ev)
  123. {
  124.     WindowPtr wind;
  125.     TWindow **info;
  126.     short part;
  127.     
  128.     part = FindWindow(ev->where, &wind);
  129.     
  130.     if (IsStatusWindow(FrontWindow()) && !IsStatusWindow(wind)) return;
  131.     
  132.     switch (part) {
  133.         case inMenuBar:
  134.             if (!IsStatusWindow(FrontWindow()))
  135.                 DoCommand(MenuSelect(ev->where));
  136.             break;
  137.         case inSysWindow:
  138.             SystemClick(ev, wind);
  139.             break;
  140.         case inDrag:
  141.             DoDrag(wind, ev->where);
  142.             break;
  143.         case inGrow:
  144.             DoGrow(wind, ev->where);
  145.             break;
  146.         case inGoAway:
  147.             if (TrackGoAway(wind, ev->where)) {
  148.                 info = (TWindow**)GetWRefCon(wind);
  149.                 if ((**info).kind == kFullGroup) {
  150.                     ShowHideGroups();
  151.                 } else {
  152.                     DoCloseWindow(wind);
  153.                 }
  154.             }
  155.             break;
  156.         case inZoomIn:
  157.         case inZoomOut:
  158.             if (TrackBox(wind, ev->where, part)) DoZoom(wind, part);
  159.             break;
  160.         case inContent:
  161.             HandleContent(wind, ev);
  162.             break;
  163.     }
  164. }
  165.